
<script type="text/javascript" src="/assets/js/jquery-1.6.2.min.js"></script>
<script language="javascript" type="text/javascript">   
$(document).ready(function(){
    $("#submit_booklet").click(function(){
        add_booklet();
    });
});

function add_booklet(){
    if(Check_booklet())
    {
       _add_booklet();
    }
}

function Check_booklet(){
    if($("#booklet_name").val()=="")
    {
		$("#msg_booklet").html("错误：书名为空");
        $("#booklet_name").focus();
        return false;
    }
    return true;
}

function _add_booklet(){

	var lock_booklet = 0;
	if ($("#lock").attr("checked") == "checked")
	{
		lock_booklet = 1;
	}

    $.ajax({
            type:"POST",
            url:"ajax/booklet/add",
			data:{
				name:$("#booklet_name").val(),
				description:$("#booklet_description").val(),
				category:$("#categorySelect").val(),
				lock:lock_booklet
			},
			dataType: "json",
            beforeSend:function(){$("#msg_booklet").html("添加中");},             
            success:function(data){
				$("#msg_booklet").html("<a target='_blank' href='/admin/picture/add/" + data.id.toString() + "'>添加成功, 点击添加图片</a>");
				$('#inputForm').each(function(){
					this.reset();
				});
			},
			error:function(jqXHR, textStatus, errorThrown){
				$("#msg_booklet").html(jqXHR.responseText);
			},
         });
    }
</script>  
 <form id="inputForm" action="/admin/booklet/new" method="post" enctype="multipart/form-data">
      <div class="row clearfix">
        <label for="booklet_name">书名:</label>
        <p><span>
          <input name="booklet_name" maxlength="100" id="booklet_name" class="inputs med required">
      </div>
      <div class="row clearfix">
        <label for="booklet_desc">描述:</label>
        <p><span>
          <textarea id="booklet_description" name="booklet_description" class="inputs med long required" rows="10"></textarea>
          </span></p>
      </div>
      <div class="row clearfix">
        <label for="desc">类别:</label>
        <select id="categorySelect" name="categorySelect" style="width:200px" multiple>
          <?php
	foreach($category_list as $category)
	{
?>
          <option value ='<?php echo $category->id; ?>'><?php echo $category->name; ?></option>
          <?php
	}
?>
        </select>
	  </div>
	   <div class="row clearfix">
		<input type="checkbox" name="lock" id="lock">加锁<br>
       </div>
      <div class="row clearfix">
        <input type="button" name="submit_booklet" id="submit_booklet" class="submit" value="Update">
      </div>
		<div id="msg_booklet"></div>
    </form>
